package com.nuedu.corejava.ch10.homework;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * 2.分别使用迭代器、foreach和for循环方式遍历ArrayList、LinkedList集合
 * @author admin
 *
 */
public class HomeWork2 {
	
	public static void main(String[] args) {
	List<Student> list1 = new ArrayList<Student>();
	LinkedList<Student> list2 = new LinkedList<Student>();
	Student[] students = new Student[5];
	for (int i = 0; i < 5; i++) {
		students[i] = new Student(i, "marik"+i, 33+i, "男");
		list1.add(students[i]);
	}
	for (int i = 0; i < 5; i++) {
		students[i] = new Student(i+1, "marik"+i, 33+i, "男");
		list2.add(students[i]);
	}
	Iterator<Student> iterator1 = list1.iterator();
	Iterator<Student> iterator2 = list2.iterator();
	while (iterator1.hasNext()) {
	System.out.println("迭代器  ArrayList：  " +iterator1.next());
		
	}
	System.out.println("---------------------------------------------");
	while (iterator2.hasNext()) {
		System.out.println("迭代器  LinkedList：  " +iterator2.next());
			
		}
	System.out.println();
	for (Student student1 : list1) {
		System.out.println("for each ArrayList： "+student1);
	}
	System.out.println("---------------------------------------------");
	for (Student student2 : list2) {
		System.out.println("for each  ArrayList： "+student2);
	}
	System.out.println();
	for (int i = 0; i < list1.size(); i++) {
		System.out.println("for  ArrayList： "+list1.get(i));
	}
	System.out.println("---------------------------------------------");
	Student s = null;
	while ((s=list2.pollLast())!=null) {
	System.out.println(s);
		
	}
	}

}
